<?php

/**
 * IndexController
 *
 * @author
 * @version
 */

require_once 'Zend/Controller/Action.php';

class IndexController extends Zend_Controller_Action
{
	protected function _getFlexigrid()
	{
		$objFlexigrid = new Tavs_JQuery_Flexigrid($this->view->url(array('action'=>'list')));

		//configura a paginacao
		$objFlexigrid
			->setCurrentPageNumber($this->_getParam('page', 1))
			->setItemCountPerPage($this->_getParam('rp', 10));

		//configura as colunas
		$objFlexigrid
			->addColumn('text', 'cliente_nome', array(
				'label' => 'Nome'
			))
			->addColumn('date', 'cliente_nascimento', array(
				'label' => 'Nascimento',
				'width' => 400
			));

		$objFlexigrid
			->addButton('Add', 'btn-add', 'editClient')
			->addButton('Edit', 'btn-edit', 'addClient');

		$objFlexigrid
			->setSelector('#tbl-testes')
			->addTableAttrib('id', 'tbl-testes');

		return $objFlexigrid;
	}

	public function indexAction()
	{
		$this->view->grid = $this->_getFlexigrid();
	}

	public function listAction()
	{
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNoRender();

		$db = Zend_Db_Table::getDefaultAdapter();

		$select = $db->select();
		$select->from('cliente', array('cliente_nome', 'cliente_nascimento'));

		echo $this->_getFlexigrid()->generateRows($select, 'cliente_id');

	}
}